from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-28 14:02:20.691602
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 28, Jun, 2022
Time: 14:02:27
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.6234
Nobs: 701.000 HQIC: -49.9820
Log likelihood: 8735.78 FPE: 1.56676e-22
AIC: -50.2079 Det(Omega_mle): 1.37924e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297839 0.057726 5.160 0.000
L1.Burgenland 0.107393 0.037925 2.832 0.005
L1.Kärnten -0.109528 0.020076 -5.456 0.000
L1.Niederösterreich 0.212452 0.079209 2.682 0.007
L1.Oberösterreich 0.102733 0.077676 1.323 0.186
L1.Salzburg 0.257493 0.040558 6.349 0.000
L1.Steiermark 0.045737 0.052835 0.866 0.387
L1.Tirol 0.109298 0.042871 2.549 0.011
L1.Vorarlberg -0.059368 0.037202 -1.596 0.111
L1.Wien 0.041287 0.068716 0.601 0.548
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.049892 0.121113 0.412 0.680
L1.Burgenland -0.034076 0.079570 -0.428 0.668
L1.Kärnten 0.041144 0.042121 0.977 0.329
L1.Niederösterreich -0.168304 0.166187 -1.013 0.311
L1.Oberösterreich 0.423798 0.162970 2.600 0.009
L1.Salzburg 0.289263 0.085093 3.399 0.001
L1.Steiermark 0.100920 0.110852 0.910 0.363
L1.Tirol 0.319221 0.089946 3.549 0.000
L1.Vorarlberg 0.028115 0.078052 0.360 0.719
L1.Wien -0.042628 0.144171 -0.296 0.767
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186607 0.029552 6.315 0.000
L1.Burgenland 0.090394 0.019415 4.656 0.000
L1.Kärnten -0.008020 0.010278 -0.780 0.435
L1.Niederösterreich 0.266075 0.040550 6.562 0.000
L1.Oberösterreich 0.136749 0.039765 3.439 0.001
L1.Salzburg 0.045930 0.020763 2.212 0.027
L1.Steiermark 0.020326 0.027048 0.751 0.452
L1.Tirol 0.091639 0.021947 4.175 0.000
L1.Vorarlberg 0.056431 0.019045 2.963 0.003
L1.Wien 0.115148 0.035178 3.273 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112051 0.030060 3.728 0.000
L1.Burgenland 0.045709 0.019749 2.314 0.021
L1.Kärnten -0.013761 0.010454 -1.316 0.188
L1.Niederösterreich 0.192362 0.041248 4.664 0.000
L1.Oberösterreich 0.301587 0.040449 7.456 0.000
L1.Salzburg 0.108492 0.021120 5.137 0.000
L1.Steiermark 0.104455 0.027514 3.797 0.000
L1.Tirol 0.103696 0.022325 4.645 0.000
L1.Vorarlberg 0.067707 0.019372 3.495 0.000
L1.Wien -0.023098 0.035783 -0.646 0.519
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.133937 0.054898 2.440 0.015
L1.Burgenland -0.051468 0.036067 -1.427 0.154
L1.Kärnten -0.044458 0.019093 -2.329 0.020
L1.Niederösterreich 0.157145 0.075329 2.086 0.037
L1.Oberösterreich 0.138151 0.073871 1.870 0.061
L1.Salzburg 0.286749 0.038571 7.434 0.000
L1.Steiermark 0.048111 0.050247 0.957 0.338
L1.Tirol 0.167415 0.040771 4.106 0.000
L1.Vorarlberg 0.093087 0.035379 2.631 0.009
L1.Wien 0.073673 0.065350 1.127 0.260
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054418 0.043647 1.247 0.212
L1.Burgenland 0.037758 0.028676 1.317 0.188
L1.Kärnten 0.051105 0.015180 3.367 0.001
L1.Niederösterreich 0.218004 0.059891 3.640 0.000
L1.Oberösterreich 0.294383 0.058732 5.012 0.000
L1.Salzburg 0.047607 0.030666 1.552 0.121
L1.Steiermark 0.001807 0.039950 0.045 0.964
L1.Tirol 0.140540 0.032415 4.336 0.000
L1.Vorarlberg 0.073780 0.028129 2.623 0.009
L1.Wien 0.081526 0.051957 1.569 0.117
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175932 0.052246 3.367 0.001
L1.Burgenland -0.002635 0.034325 -0.077 0.939
L1.Kärnten -0.063128 0.018170 -3.474 0.001
L1.Niederösterreich -0.079791 0.071691 -1.113 0.266
L1.Oberösterreich 0.190400 0.070303 2.708 0.007
L1.Salzburg 0.057586 0.036708 1.569 0.117
L1.Steiermark 0.236687 0.047820 4.950 0.000
L1.Tirol 0.498558 0.038801 12.849 0.000
L1.Vorarlberg 0.044845 0.033670 1.332 0.183
L1.Wien -0.056048 0.062193 -0.901 0.367
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169504 0.059346 2.856 0.004
L1.Burgenland -0.012433 0.038990 -0.319 0.750
L1.Kärnten 0.063842 0.020640 3.093 0.002
L1.Niederösterreich 0.206756 0.081433 2.539 0.011
L1.Oberösterreich -0.078691 0.079856 -0.985 0.324
L1.Salzburg 0.213396 0.041696 5.118 0.000
L1.Steiermark 0.125814 0.054319 2.316 0.021
L1.Tirol 0.067006 0.044074 1.520 0.128
L1.Vorarlberg 0.119434 0.038246 3.123 0.002
L1.Wien 0.127719 0.070645 1.808 0.071
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.363460 0.034326 10.588 0.000
L1.Burgenland 0.007518 0.022552 0.333 0.739
L1.Kärnten -0.023576 0.011938 -1.975 0.048
L1.Niederösterreich 0.216338 0.047101 4.593 0.000
L1.Oberösterreich 0.205030 0.046189 4.439 0.000
L1.Salzburg 0.044107 0.024117 1.829 0.067
L1.Steiermark -0.014560 0.031418 -0.463 0.643
L1.Tirol 0.105658 0.025493 4.145 0.000
L1.Vorarlberg 0.069243 0.022122 3.130 0.002
L1.Wien 0.029049 0.040861 0.711 0.477
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037734 0.136949 0.193666 0.155332 0.114553 0.101801 0.058041 0.217589
Kärnten 0.037734 1.000000 -0.015133 0.134347 0.056094 0.095367 0.435634 -0.053069 0.093718
Niederösterreich 0.136949 -0.015133 1.000000 0.336188 0.141478 0.294354 0.092023 0.177208 0.311050
Oberösterreich 0.193666 0.134347 0.336188 1.000000 0.227636 0.325417 0.176555 0.163949 0.265118
Salzburg 0.155332 0.056094 0.141478 0.227636 1.000000 0.137624 0.117248 0.139140 0.131199
Steiermark 0.114553 0.095367 0.294354 0.325417 0.137624 1.000000 0.144802 0.129390 0.073723
Tirol 0.101801 0.435634 0.092023 0.176555 0.117248 0.144802 1.000000 0.113491 0.141605
Vorarlberg 0.058041 -0.053069 0.177208 0.163949 0.139140 0.129390 0.113491 1.000000 0.005269
Wien 0.217589 0.093718 0.311050 0.265118 0.131199 0.073723 0.141605 0.005269 1.000000